#include "StdAfx.h"
#include "ResManager.h"
#include "Resource.h"

using namespace RenderSystem;

ResManager::ResManager( const String& strResType )
	:m_strResType(strResType)
{
	assert( !strResType.empty() );
}


ResManager::~ResManager(void)
{
}

Resource* ResManager::Create( const String& strResId )
{
	if( strResId.empty() )
		return NULL;

	Resource* pFindRes = this->FindResource( strResId );
	if( pFindRes != NULL )
		return pFindRes;

	Resource* pNewResource = this->_CreateImp( strResId );
	if( pNewResource != NULL )
		m_Resources.push_back( pNewResource );

	return pNewResource;
}

Resource* ResManager::FindResource( const String& strResId ) const
{
	ResourcesConstIterator itrRes = m_Resources.begin();
	for( ; itrRes != m_Resources.end(); ++itrRes )
	{
		if( strResId == (*itrRes)->GetResourceId() )
			return *itrRes;
	}

	return NULL;
}


